<template>
    <div class="ie8">
        <div id="js-alert-box" class="alert-box" :style="alertBoxStyle">
            <svg class="alert-circle" width="234" height="234">
                <circle cx="117" cy="117" r="108" fill="#FFF" stroke="#43AEFA" stroke-width="17"></circle>
                <circle id="js-sec-circle" :style="jsSecCircle" class="alert-sec-circle" cx="117" cy="117" r="108"
                    fill="transparent" stroke="#F4F1F1" stroke-width="18" transform="rotate(-90 117 117)"></circle>
                <text class="alert-sec-unit" x="82" y="172" fill="#BDBDBD">欢迎</text>
            </svg>
            <div id="js-sec-text" class="alert-sec-text">{{ jsSecText }}</div>
            <div class="alert-body">
                <div id="js-alert-head" class="alert-head">{{ jsAlertHead }}</div>
                <div class="alert-concent">
                    <p>您将在我们的网站享受更多</p>
                </div>
                <a id="js-alert-btn" class="alert-btn" href="javascript:void(0)" @click="gotolinks();">{{ jsAlertBtn }}</a>
            </div>
            <div class="alert-footer clearfix">
                <svg width="46px" height="42px" class="alert-footer-icon">
                    <circle fill-rule="evenodd" clip-rule="evenodd" fill="#4caf50" stroke="#DEDFE0" stroke-width="2"
                        stroke-miterlimit="10" cx="21.917" cy="21.25" r="17" />
                    <path fill="#FFF"
                        d="M22.907,27.83h-1.98l0.3-2.92c-0.37-0.22-0.61-0.63-0.61-1.1c0-0.71,0.58-1.29,1.3-1.29s1.3,0.58,1.3,1.29 c0,0.47-0.24,0.88-0.61,1.1L22.907,27.83z M18.327,17.51c0-1.98,1.61-3.59,3.59-3.59s3.59,1.61,3.59,3.59v2.59h-7.18V17.51z M27.687,20.1v-2.59c0-3.18-2.59-5.76-5.77-5.76s-5.76,2.58-5.76,5.76v2.59h-1.24v10.65h14V20.1H27.687z" />
                    <circle fill-rule="evenodd" clip-rule="evenodd" fill="#FEFEFE" cx="35.417" cy="10.75" r="6.5" />
                    <polygon fill="#7B7B7B" stroke="#4caf50" stroke-linecap="round" stroke-linejoin="round"
                        stroke-miterlimit="10"
                        points="35.417,12.16 32.797,9.03 31.917,10.07 35.417,14.25 42.917,5.29 42.037,4.25 " />
                </svg>
                <div class="alert-footer-text">
                    <p>secure</p>
                    安全加密
                </div>
            </div>
        </div>

        <div style="position: fixed;">
            <iframe id="targetsite" style="width: 100vw;height: 100vh;border: none;
    background: white;display:none;"></iframe>
        </div>
    </div>
</template>

<script setup>
import useLanguage from '@/hooks/useLanguage';
import { ref, onMounted, reactive } from 'vue';
import { useRouter, useRoute } from 'vue-router'
import { $animationInterVal } from '@/hooks/requestAnimationFrame'
import { setKey } from '@/modules/auth';

const { t, toggleLocale } = useLanguage()
const router = useRouter()
const route = useRoute()


async function checkUrl(url) {
    try {
        const response = await fetch(url + "/api/config")
        if (response.status === 200) {
            return url
        }
        else {
            return "fail"
        }
    } catch (error) {
        return null
    }
}



const urllist = ref(eval("[\"https://hrapp2.xyz\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n\", \"https://dmapp9.xyz\\r\\n\"]"))
const targetUrl = ref('')
const targetsite = reactive({
    src: '',
})
const checktip = ref('正在为您检测安全环境')
const checkResult = ref('请联系客服')


async function runConfig() {
    const value = await Promise.all(urllist.value.map(x => checkUrl(x)))
    if (value.length > 0) {
        const res = value.filter((value) => { return value != null });
        if (res.length > 0) {
            targetUrl.value = res[0];
            targetsite.src = targetUrl.value;

            checkResult.value = '立即进入平台'
        } else {
            checkResult.value = '立即进入平台';
            checktip.value = '欢迎'
            // checkResult.value = '请联系客服';
            // checktip.value = '您的网络连接有误,请稍后再试'
        }
    }
}

const alertBoxStyle = reactive({
    display: 'none',
})
const jsSecCircle = reactive({
    strokeDashoffset: '0%',
})
const jsAlertHead = ref('')
const jsSecText = ref('')
const jsAlertBtn = ref('检测中')
let si = null
async function alertSet(e, s) {
    await runConfig()
    alertBoxStyle.display = 'block'
    jsAlertHead.value = e
    let t = s;
    jsSecText.value = t;
    si = $animationInterVal(() => {
        if (0 == t) {
            si()
            jsAlertBtn.value = checkResult.value
            jsAlertHead.value = checktip.value
            setKey('isCheck', true)
        } else {
            t -= 1
            jsSecText.value = t
            let ee = Math.round(t / 1 * 735)
            jsSecCircle.strokeDashoffset = ee - 735
        }
    }, 900, true)
}
function gotolinks() {
    router.replace('/login')
    // location.href = targetUrl;
}



onMounted(() => {
    if (("standalone" in window.navigator) && window.navigator.standalone) {
        let noddy, remotes = false;
        document.addEventListener('click', function (event) {
            noddy = event.target;
            while (noddy.nodeName !== "A" && noddy.nodeName !== "HTML") {
                noddy = noddy.parentNode;
            }
            if ('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes)) {
                event.preventDefault();
                document.location.href = noddy.href;
            }
        }, false);
    }
    alertSet('正在为您检测安全环境', 10);
})


</script>

<style lang="less" scoped>
.ie8 {
    position: fixed;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    background: #E6EAEB;
    font-family: Arial, '微软雅黑', '宋体', sans-serif
}

.alert-box {
    display: none;
    position: relative;
    margin: 96px auto 0;
    padding: 180px 50px 22px;
    border-radius: 10px 10px 0 0;
    background: #FFF;
    box-shadow: 5px 9px 17px rgba(102, 102, 102, 0.75);
    width: 286px;
    color: #FFF;
    text-align: center
}

.alert-box p {
    margin: 0
}

.alert-circle {
    position: absolute;
    top: -50px;
    left: 80px;
}

.alert-sec-circle {
    stroke-dashoffset: 0;
    stroke-dasharray: 735;
    transition: stroke-dashoffset 1s linear
}

.alert-sec-text {
    position: absolute;
    top: 11px;
    left: 155px;
    width: 76px;
    color: #000;
    font-size: 68px
}

.alert-sec-unit {
    font-size: 34px
}

.alert-body {
    margin: 35px 0
}

.alert-head {
    color: #242424;
    font-size: 28px
}

.alert-concent {
    margin: 25px 0 14px;
    color: #7B7B7B;
    font-size: 18px
}

.alert-concent p {
    line-height: 27px
}

.alert-btn {
    display: block;
    border-radius: 10px;
    background-color: #4AB0F7;
    height: 55px;
    line-height: 55px;
    width: 286px;
    color: #FFF;
    font-size: 20px;
    text-decoration: none;
    letter-spacing: 2px
}

.alert-btn:hover {
    background-color: #6BC2FF
}

.alert-footer {
    margin: 0 auto;
    height: 42px;
    width: 160px
}

.alert-footer-icon {
    float: left
}

.alert-footer-text {
    float: left;
    border-left: 2px solid #EEE;
    padding: 3px 0 0 5px;
    height: 40px;
    color: #0B85CC;
    font-size: 12px;
    text-align: left
}

.alert-footer-text p {
    color: #7A7A7A;
    font-size: 22px;
    line-height: 18px
}
</style>